<template>
  <div class="campus-binhai">
    <h1>温州理工滨海校区</h1>
    <div class="search-container">
      <input v-model="studentId" placeholder="请输入学号" @keyup.enter="searchStudent" />
      <button @click="searchStudent">查找</button>
    </div>
    <div v-if="studentInfo" class="student-info">
      <h2>学生信息</h2>
      <p>学号: {{ studentInfo.id }}</p>
      <p>姓名: {{ studentInfo.name }}</p>
      <p>专业: {{ studentInfo.major }}</p>
    </div>
    <div v-if="error" class="error-message">
      {{ error }}
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      studentId: '',
      studentInfo: null,
      error: ''
    };
  },
  methods: {
    searchStudent() {
      // 模拟学生数据
      const students = [
        { id: '2023001', name: '张三', major: '计算机科学' },
        { id: '2023002', name: '李四', major: '软件工程' },
        { id: '2023003', name: '王五', major: '网络工程' }
      ];

      const foundStudent = students.find(student => student.id === this.studentId);

      if (foundStudent) {
        this.studentInfo = foundStudent;
        this.error = '';
      } else {
        this.studentInfo = null;
        this.error = '未找到该学号的学生信息';
      }
    }
  }
};
</script>

<style scoped>
.campus-binhai {
  text-align: center;
  padding: 20px;
}

.search-container {
  margin: 20px 0;
}

input {
  padding: 8px;
  width: 200px;
}

button {
  padding: 8px 16px;
  background-color: #4CAF50;
  color: white;
  border: none;
  cursor: pointer;
}

.student-info {
  margin-top: 20px;
  background-color: #f9f9f9;
  padding: 15px;
  border-radius: 5px;
}

.error-message {
  color: red;
  margin-top: 15px;
}
</style>